package com.wang.aspect.aspect;

import com.wang.aspect.DynamicDataSource;
import com.wang.aspect.annotation.TargetDataSource;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

/**
 * @author: wangning1@abupdate.com
 * @date: 2023-12-19 14:48
 **/
@Component
@Aspect
public class TargetDataSourceAspect {

    //前置，方法调用之前配置数据源
    //com.wang.aspect.controller包下所有的类只要有@TargetDataSource注解，则会被aop增强处理
    @Before("within(com.wang.aspect.controller.*) && @annotation(targetDataSource)")
    public void before(JoinPoint point, TargetDataSource targetDataSource){
        String value = targetDataSource.value();
        DynamicDataSource.flag.set(value);
    }

}